// 开始登录代码的编写
const btnpwd = document.querySelector('.btnPwd');
const btnphone = document.querySelector('.btnPhone');
const enterIn = document.querySelector('.btnLogin');
// console.log(btnphone, btnpwd, login)
// 开始注册代码的编写
// 1.获取所有需要处理的节点
// const pwd = document.querySelector('.btn-pwd');
// const miphone = document.querySelector('.btn-phone');
// const repwd = document.querySelector('.btn-repwd');
// const regis = document.querySelector('.btn-register');
// console.log(pwd, phone, repwd, regis)

// 提升全局变量
let phone,
    password;
let pe,
    pw;
console.log(enterIn)
enterIn.addEventListener('click', function (evt) {
    if (!!btnpwd.value && !!btnphone.value) {
        phone = btnphone.value;
        password = btnpwd.value;
        logIn();
    }
});
const logImg = document.querySelector('#loginFor');
console.log(logImg)
// 登录
function logIn() {
    Ajax({
        url: 'http://localhost:3000/login/cellphone',
        params: {
            phone: phone,
            password: password,
        },
        type: 'get'
    }).then(function (res) {
        console.log(res)
        if (res.loginType == 1) {
            pe = btnphone.value;
            pw = btnpwd.value;
            var str = `<img src="${res.profile.avatarUrl}" style="width:65px; height: 65px;border-radius:  34px;"/>`;
            let nickname = res.profile.nickname;
            let backImg = res.profile.backgroundUrl;
            localStorage.setItem('img', str);
            localStorage.setItem('nickname', nickname);
            localStorage.setItem('backImg', backImg);
            location.href = './index.html'
        }
    })
}
// 登录状态
function logtype() {
    Ajax({
        url: 'http://localhost:3000/logout',
        params: {},
        type: 'get'
    }).then(function (res) {
        console.log(res);
    })
}
// 退出登录
function logOut() {
    Ajax({
        url: 'http://localhost:3000/logout',
        params: {},
        type: 'get'
    }).then(function (res) {
        console.log(res)
    })
}
logtype();
